package thread;

public class SyncDemo4 {
    public static void main(String[] args) {
        Boo boo = new Boo();
        new Thread(()->boo.methodA()).start();
        new Thread(()->boo.methodB()).start();
    }
}
class Boo{
    public synchronized void methodA(){
        Thread t = Thread.currentThread();
        System.out.println(t.getName() + "：正在执行A方法");
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(t.getName() + "：执行A方法完毕");
    }
    public void methodB(){
        synchronized (this) {
            Thread t = Thread.currentThread();
            System.out.println(t.getName() + "：正在执行B方法");
            try {
                Thread.sleep(4000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t.getName() + "：执行B方法完毕");
        }
    }
}